<template>
  <el-tabs
    type="border-card"
    stretch
  >
    <el-tab-pane
      label="充值"
      index="charge"
    >
      <el-form
        label-width="110px"
        ref="chargeForm"
        :rules="chargeFormRules"
        :model="chargeFormData"
      >
        <el-form-item
          label="充值金额"
          prop="money"
        >
          <el-input
            v-model="chargeFormData.money"
            type="number"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item
          label="获得"
        >
          <span>{{chargeFormData.money}} 欢乐值</span>
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            :style="{ width: '100%' }"
            @click="handleCharge"
          >确认充值</el-button>
        </el-form-item>
      </el-form>
    </el-tab-pane>
    <el-tab-pane
      label="成为会员"
      index="member"
    >
      <el-form
        label-width="110px"
        ref="memberForm"
        :model="memberFormData"
      >
        <el-form-item
          label="会员价格"
          prop="money"
        >
          <span>1024 元</span>
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            :style="{ width: '100%' }"
            @click="handleBeMemeber"
          >确认购买</el-button>
        </el-form-item>
      </el-form>
    </el-tab-pane>
  </el-tabs>
</template>

<script>
export default {
  name: 'Charge',
  data() {
    return {
      chargeFormData: {
        money: 100,
      },
      chargeFormRules: {
        money: [{ required: true, message: '请输入充值金额!', trigger: 'blur' }],
      },
      memberFormData: {},
    };
  },
  methods: {
    handleCharge() {
      this.$refs.chargeForm.validate((valid) => {
        if (valid) {
          this.$router.push('/payment');
        }
      });
    },
    handleBeMemeber() {
      this.$router.push('/payment');
    },
  },
};
</script>

<style scoped>
.el-tabs {
  width: 450px;
  margin: 50px auto;
}

.el-form-item {
  padding: 0 20px;
}
</style>
